﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SharpDiary.Diary
{
    public partial class CalendarBoard : UserControl
    {
        private DateTime _date = DateTime.Now;

        /// <summary>
        /// 获取或设置显示日期。
        /// </summary>
        public DateTime Date
        {
            get { return _date; }
            set
            {
                if (value == _date) { return; }
                _date = value;
                DisplayDate();
            }
        }

        public CalendarBoard()
        {
            InitializeComponent();

            ResizeRedraw = true;
            DoubleBuffered = true;

            DisplayDate();
        }

        /// <summary>
        /// 显示日期。
        /// </summary>
        private void DisplayDate()
        {
            lblMonth.Text = GetMonthString(_date.Month);
            lblDay.Text = _date.Day.ToString();
            lblWeek.Text = GetWeek(_date.DayOfWeek);

            //星期六显示绿色，星期日显示红色
            if (_date.DayOfWeek == DayOfWeek.Saturday)
            {
                lblDay.ForeColor = Color.DarkGreen;
            }
            else if (_date.DayOfWeek == DayOfWeek.Sunday)
            {
                lblDay.ForeColor = Color.DarkRed;
            }
            else
            {
                lblDay.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
            }

            lblWeek.ForeColor = lblDay.ForeColor;

            toolTip.SetToolTip(this, _date.ToLongDateString());
            foreach (Control control in Controls)
            {
                toolTip.SetToolTip(control, _date.ToLongDateString());
            }
        }

        /// <summary>
        /// 获取星期字符串。
        /// </summary>
        /// <param name="dayOfWeek"></param>
        /// <returns></returns>
        private string GetWeek(DayOfWeek dayOfWeek)
        {
            switch (dayOfWeek)
            {
                case DayOfWeek.Sunday: return "星期日";
                case DayOfWeek.Monday: return "星期一";
                case DayOfWeek.Tuesday: return "星期二";
                case DayOfWeek.Wednesday: return "星期三";
                case DayOfWeek.Thursday: return "星期四";
                case DayOfWeek.Friday: return "星期五";
                case DayOfWeek.Saturday: return "星期六";
                default: return "未知";
            }
        }

        /// <summary>
        /// 获取月份。
        /// </summary>
        /// <param name="month">月份数字</param>
        /// <returns></returns>
        private string GetMonthString(int month)
        {
            switch (month)
            {
                case 1: return "一月";
                case 2: return "二月";
                case 3: return "三月";
                case 4: return "四月";
                case 5: return "五月";
                case 6: return "六月";
                case 7: return "七月";
                case 8: return "八月";
                case 9: return "九月";
                case 10: return "十月";
                case 11: return "十一月";
                case 12: return "十二月";
                default: return "未知";
            }
        }
    }
}
